home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / ObjectTcl-1.1 / CdlRtn.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  8.7 KB  |  341 lines

  1. /*  _ __ ___ _
  2.  * | |\ /  /| |  $Id: CdlRtn.C,v 1.7 1995/05/09 16:14:10 deans Exp $
  3.  * | | /  / | |  Copyright (C) 1995 IXI Limited.
  4.  * |_|/__/_\|_|  IXI Limited, Cambridge, England.
  5.  *
  6.  * Component   : CdlRtn.C
  7.  *
  8.  * Author      : Dean Sheehan (deans@x.co.uk)
  9.  *
  10.  * Description : Contains the implementation of CdlRtn ans subclasses that
  11.  *               model the various types of return arguments from methods.
  12.  *
  13.  * License     :
  14.             Object Tcl License & Copyright
  15.             ------------------------------
  16.  
  17. IXI Object Tcl software, both binary and source (hereafter, Software) is copyrighted by IXI Limited (IXI), and ownership remains with IXI. 
  18.  
  19. IXI grants you (herafter, Licensee) a license to use the Software for academic, research and internal business purposes only, without a fee. Licensee may distribute the binary and source code (if required) to third parties provided that the copyright notice and this statement appears on all copies and that no charge is associated with such copies. 
  20.  
  21. Licensee may make derivative works. However, if Licensee distributes any derivative work based on or derived from the Software, then Licensee will (1) notify IXI regarding its distribution of the derivative work, and (2) clearly notify users that such derivative work is a modified version and not the original IXI Object Tcl distributed by IXI. IXI strongly recommends that Licensee provide IXI the right to incorporate such modifications into future releases of the Software under these license terms. 
  22.  
  23. Any Licensee wishing to make commercial use of the Software should contact IXI, to negotiate an appropriate license for such commercial use. Commercial use includes (1) integration of all or part of the source code into a product for sale or license by or on behalf of Licensee to third parties, or (2) distribution of the binary code or source code to third parties that need it to utilize a commercial product sold or licensed by or on behalf of Licensee. 
  24.  
  25. IXI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. IXI SHALL NOT BE LIABLE FOR ANY DAMAGES WHATSOEVER SUFFERED BY THE USERS OF THIS SOFTWARE. 
  26.  
  27. Copyright (C) 1995, IXI Limited 
  28.  
  29. By using or copying this Software, Licensee agrees to abide by the copyright law and all other applicable laws of England and the U.S., including, but not limited to, export control laws, and the terms of this license. IXI shall have the right to terminate this license immediately by written notice upon Licensee's breach of, or non-compliance with, any of its terms. Licensee may be held legally responsible for any copyright infringement that is caused or encouraged by Licensee's failure to abide by the terms of this license. 
  30.  
  31. Comments and questions are welcome and can be sent to
  32. otcl@x.co.uk 
  33.  
  34. For more information on copyright and licensing issues, contact: 
  35. Legal Department, IXI Limited, Vision Park, Cambridge CB4 4ZR,
  36. ENGLAND. 
  37.  
  38.  *
  39.  */
  40.  
  41. // System Includes
  42. #include <stdlib.h>
  43. #include <string.h>
  44.  
  45. // Local Include
  46. #include "CdlRtn.H"
  47. #include "CdlFile.H"
  48.  
  49. CdlRtn *CdlRtn::exemplarHead = NULL;
  50. CdlRtn *CdlRtn::exemplarTail = NULL;
  51.  
  52. CdlRtn::CdlRtn (int e)
  53. {
  54.    nextExemplar = NULL;
  55.    if (e == 1)
  56.    {
  57.      // This is an exemplar
  58.      if (exemplarTail == NULL)
  59.      {
  60.         exemplarHead = exemplarTail = this;
  61.      }
  62.      else
  63.      {
  64.         exemplarTail->nextExemplar = this;
  65.         exemplarTail = this;
  66.      }
  67.    }
  68. }
  69.  
  70. CdlRtn::~CdlRtn ()
  71. {
  72. }
  73.  
  74. int CdlRtn::setArgs (int, char *[])
  75. {
  76.    return 1;
  77. }
  78.  
  79. CDL_RTN_DEF(CdlIntRtn,int)
  80.  
  81. CdlIntRtn::~CdlIntRtn ()
  82. {
  83. }
  84.  
  85. void CdlIntRtn::genPrototype (ofstream &of)
  86. {
  87.    of << "int "; 
  88. }
  89.  
  90. void CdlIntRtn::declareLocal (ofstream &of, CdlIndent tab)
  91. {
  92.    of << tab << "int rtn = ";
  93. }
  94.  
  95. void CdlIntRtn::localName (ofstream &of)
  96. {
  97.    of << "rtn";
  98. }
  99.  
  100. void CdlIntRtn::postProcess (ofstream &of, CdlIndent tab)
  101. {
  102.    of << tab << "Otcl::setTclResult(i,\"%d\",rtn);" << endl;
  103. }
  104.  
  105. void CdlIntRtn::returnFromTclInterp (char *interpName, ofstream &of,
  106.                                      CdlIndent tab)
  107. {
  108.    of << tab << "return atoi(" << interpName << "->result);" << endl;
  109. }
  110.  
  111. CDL_RTN_DEF(CdlFloatRtn,float)
  112.  
  113. CdlFloatRtn::~CdlFloatRtn ()
  114. {
  115. }
  116.  
  117. void CdlFloatRtn::genPrototype (ofstream &of)
  118. {
  119.    of << "float "; 
  120. }
  121.  
  122. void CdlFloatRtn::declareLocal (ofstream &of, CdlIndent tab)
  123. {
  124.    of << tab << "float rtn = ";
  125. }
  126.  
  127. void CdlFloatRtn::localName (ofstream &of)
  128. {
  129.    of << "rtn";
  130. }
  131.  
  132. void CdlFloatRtn::postProcess (ofstream &of, CdlIndent tab)
  133. {
  134.    of << tab << "Otcl::setTclResult(i,\"%f\",rtn);" << endl;
  135. }
  136.  
  137. void CdlFloatRtn::returnFromTclInterp (char *interpName, ofstream &of,
  138.                                      CdlIndent tab)
  139. {
  140.    of << tab << "return atof(" << interpName << "->result);" << endl;
  141. }
  142.  
  143. CDL_RTN_DEF(CdlDoubleRtn,double)
  144.  
  145. CdlDoubleRtn::~CdlDoubleRtn ()
  146. {
  147. }
  148.  
  149. void CdlDoubleRtn::genPrototype (ofstream &of)
  150. {
  151.    of << "double "; 
  152. }
  153.  
  154. void CdlDoubleRtn::declareLocal (ofstream &of, CdlIndent tab)
  155. {
  156.    of << tab << "double rtn = ";
  157. }
  158.  
  159. void CdlDoubleRtn::localName (ofstream &of)
  160. {
  161.    of << "rtn";
  162. }
  163.  
  164. void CdlDoubleRtn::postProcess (ofstream &of, CdlIndent tab)
  165. {
  166.    of << tab << "Otcl::setTclResult(i,\"%f\",rtn);" << endl;
  167. }
  168.  
  169. void CdlDoubleRtn::returnFromTclInterp (char *interpName, ofstream &of,
  170.                                         CdlIndent tab)
  171. {
  172.    of << tab << "return strtod(" << interpName << "->result,(char **)NULL);" << endl;
  173. }
  174.  
  175. CDL_RTN_DEF(CdlStrRtn,str)
  176.  
  177. CdlStrRtn::~CdlStrRtn ()
  178. {
  179. }
  180.  
  181. void CdlStrRtn::genPrototype (ofstream &of)
  182. {
  183.    of << "char *"; 
  184. }
  185.  
  186. void CdlStrRtn::declareLocal (ofstream &of, CdlIndent tab)
  187. {
  188.    of << tab << "char *rtn = ";
  189. }
  190.  
  191. void CdlStrRtn::localName (ofstream &of)
  192. {
  193.    of << "rtn";
  194. }
  195.  
  196. void CdlStrRtn::postProcess (ofstream &of, CdlIndent tab)
  197. {
  198.    of << tab << "Tcl_SetResult(Otcl::tclInterp,rtn,TCL_VOLATILE);" << endl;
  199. }
  200.  
  201. void CdlStrRtn::returnFromTclInterp (char *interpName, ofstream &of,
  202.                                      CdlIndent tab)
  203. {
  204.    of << tab << "return (" << interpName << "->result);" << endl;
  205. }
  206.  
  207. CDL_RTN_DEF(CdlObptrRtn,obptr)
  208.  
  209. CdlObptrRtn::~CdlObptrRtn ()
  210. {
  211.    if (className)
  212.    {
  213.       free(className);
  214.    }
  215. }
  216.  
  217. int CdlObptrRtn::setArgs (int argc, char *argv[])
  218. {
  219.    if (argc != 1)
  220.    {
  221.       return 0;
  222.    }
  223.    className = strdup(argv[0]);
  224.    return 1;
  225. }
  226.  
  227. void CdlObptrRtn::genPrototype (ofstream &of)
  228. {
  229.    of << className << " *"; 
  230. }
  231.  
  232. void CdlObptrRtn::declareLocal (ofstream &of, CdlIndent tab)
  233. {
  234.    of << tab << className << " *rtn = ";
  235. }
  236.  
  237. void CdlObptrRtn::localName (ofstream &of)
  238. {
  239.    of << "rtn";
  240. }
  241.  
  242. void CdlObptrRtn::postProcess (ofstream &of, CdlIndent tab)
  243. {
  244.    of << tab << "if (rtn == NULL)" << endl;
  245.    of << tab << "{" << endl;
  246.    tab++;
  247.    of << tab << "Otcl::setTclResult(i,\"\");" << endl;
  248.    tab--;
  249.    of << tab << "}" << endl;
  250.    of << tab << "else" << endl;
  251.    of << tab << "{" << endl;
  252.    tab++;
  253.    of << tab << "Otcl::setTclResult(i,\"%s\"," 
  254.       << "((" << className << OTCL_PART_SUFFIX << "*)" 
  255.       << "rtn)->giveOwner()->getSelf()"
  256.       << ");" << endl;
  257.    tab--;
  258.    of << tab << "}" << endl;
  259. }
  260.  
  261. void CdlObptrRtn::returnFromTclInterp (char *interpName, ofstream &of,
  262.                                      CdlIndent tab)
  263. {
  264.    of << tab << "return (" 
  265.       << "(" << className << "*) Otcl::otclPtr->obrefToCpp("
  266.       << interpName << "->result ,\"" << className << "\")"
  267.       << ");" << endl;
  268. }
  269.  
  270.  
  271. CDL_RTN_DEF(CdlObrefRtn,obref)
  272.  
  273. CdlObrefRtn::~CdlObrefRtn ()
  274. {
  275.    if (className)
  276.    {
  277.       free(className);
  278.    }
  279.    shouldNew = CDL_FALSE;
  280. }
  281.  
  282. int CdlObrefRtn::setArgs (int argc, char *argv[])
  283. {
  284.    if (argc < 1 || argc > 2)
  285.    {
  286.       return 0;
  287.    }
  288.    if (argc == 1)
  289.    {
  290.       className = strdup(argv[0]);
  291.    }
  292.    else
  293.    {
  294.       shouldNew = (strcmp(argv[0],"-new") == 0 ?  CDL_TRUE : CDL_FALSE);
  295.       className = strdup(argv[1]);
  296.    }
  297.    return 1;
  298. }
  299.  
  300. void CdlObrefRtn::genPrototype (ofstream &of)
  301. {
  302.    of << className << " &"; 
  303. }
  304.  
  305. void CdlObrefRtn::declareLocal (ofstream &of, CdlIndent tab)
  306. {
  307.    of << tab << className << " &rtn = ";
  308. }
  309.  
  310. void CdlObrefRtn::localName (ofstream &of)
  311. {
  312.    of << "rtn";
  313. }
  314.  
  315. void CdlObrefRtn::postProcess (ofstream &of, CdlIndent tab)
  316. {
  317.    //new <class>_otcl(((className&)rtn));
  318.  
  319.    if (shouldNew == CDL_TRUE)
  320.    {
  321.       of << tab << "Otcl::setTclResult(i,\"%s\","
  322.       << "(new " << className << OTCL_PART_SUFFIX << "(" << "((" << className << "&)rtn) ))->giveOwner()->getSelf()" << ");" << endl;
  323.    }
  324.    else 
  325.    {
  326.       of << tab << "Otcl::setTclResult(i,\"%s\","
  327.          << "((" << className << OTCL_PART_SUFFIX << "&)" 
  328.          << "rtn).giveOwner()->getSelf()"
  329.          << ");" << endl;
  330.    }
  331. }
  332.  
  333. void CdlObrefRtn::returnFromTclInterp (char *interpName, ofstream &of,
  334.                                      CdlIndent tab)
  335. {
  336.    of << tab << "return (" 
  337.       << "*(" << className << "*) Otcl::otclPtr->obrefToCpp("
  338.       << interpName << "->result ,\"" << className << "\")"
  339.       << ");" << endl;
  340. }
  341.